﻿using Cdn.Blogger.Models;
using System;
using System.Web.Mvc;
using XZen.Blogger;
namespace Cdn.Blogger.Controllers
{
    public class UIController : Controller
    {
        public const string INSTANCE = "BlogService.Instance";
        private BlogService service;
        public BlogService Service
        {
            get
            {
                return this.service;
            }
            set
            {
                this.service = value;
            }
        }
        public bool IsServiceNotInitiated
        {
            get
            {
                this.service = (BlogService)base.Session["BlogService.Instance"];
                return this.service == null;
            }
        }
        protected Exception Init(CDNSetting setting)
        {
            Exception result;
            try
            {
                this.service = BlogService.Create(setting.User, setting.Subscription);
                this.service.Login(setting.UserName, setting.Password, setting.ContentUri);
                base.Session["BlogService.Instance"] = this.service;
            }
            catch (Exception exds)
            {
                if (!base.Request.IsLocal)
                {
                    result = exds;
                    return result;
                }
                this.service = BlogService.Create("demo", "cool");
                this.service.Login("demo", "$Demo2012", "http://localhost:16444");
                base.Session["BlogService.Instance"] = this.service;
            }
            result = null;
            return result;
        }
    }
}
